package video

import (
	"gorm.io/gorm"
	"supervideo/pkg/app"
	"supervideo/pkg/database"
	"supervideo/pkg/paginator"

	"github.com/gin-gonic/gin"
	"gorm.io/gorm/clause"
)

func Get(idstr string) (Video Video) {
	database.DB.Preload(clause.Associations).Where("id", idstr).First(&Video)
	return
}

// Paginate 分页内容
func Paginate(c *gin.Context, perPage int, query ...*gorm.DB) (video []Video, paging paginator.Paging) {

	q := database.DB.Model(Video{})
	if len(query) > 0 {
		q = query[0]
	}

	paging = paginator.Paginate(
		c,
		q,
		&video,
		app.V1URL(database.TableName(&Video{})),
		perPage,
	)

	return
}
